using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Ent.Voice.Show;
using Ent.Voice.Nomination;
using Ent.Web.Helper;
using System.Collections.Generic;
public partial class ShowEvent : System.Web.UI.Page
{
    int count = 10;
    protected void Page_Load(object sender, EventArgs e)
    {
        count = eventSet.MaxOnScreen;
        btnNext.Attributes.Add("onmouseover", "this.src='Images/dj/nexth.gif'");
        btnNext.Attributes.Add("onmouseout", "this.src='Images/dj/next.gif'");
        btnPrev.Attributes.Add("onmouseover", "this.src='Images/dj/prevh.gif'");
        btnPrev.Attributes.Add("onmouseout", "this.src='Images/dj/prev.gif'");
        SetEvent();
    }
    private void SetEvent()
    {
        try
        {
            int id = MathFunction.ConvertToInteger(Request.QueryString["id"]);
            lblNomination.Text = Common.GetImageTextLink("Nominate.aspx?id=" + id, "Images/dj/entry.gif", ResourceHelper.Get("MSG_SubmitNomination"), 20);
            if (Session["USERID"] != null)
            {
                UserNomination uNom = Nomination.GetUserNomination(id, Session["USERID"].ToString());
                if (uNom.Status == NominationStatus.Nominated)
                    lblNomination.Text = Common.GetImageTextLink("ShowEntry.aspx?id=" + uNom.EntryId.ToString(), "Images/dj/entry.gif", ResourceHelper.Get("MSG_ViewNomination"), 20);
            }

            int pi = MathFunction.ConvertToInteger(Request.QueryString["pi"], 0);
            string c = Request.QueryString["c"];
            int start = pi * count + 1;
            int total = 0;
            Event ev = Event.GetEvent(id, start, count, false, StringHelper.ConvertToString(Session["USERID"]), ref total);
            tblTrans.Visible = false;
            lblMessage.Visible = false;
            cAccess.Visible = false;
            if (ev == null)
            {
                lblMessage.Visible = true;
                throw new Exception(ResourceHelper.Get("MSG_InvalidAccess"));
            }
            this.Page.Title = ev.Name + " - " + ResourceHelper.Get("SITE_Title");
            if (ev.Entries != null && ev.Entries.Length != 0)
            {
                string param = Common.RetainParam(new string[] { "c" });
                if (param != "") param = "&" + param;
                imgSlide.Attributes.Add("onclick", "window.location.href='ShowEntry.aspx?id=" + ((Entry)ev.Entries.GetValue(0)).Id + param + "'");
            }
            lblEventTitle.Font.Bold = true;
            lblEventTitle.Text = StringHelper.RestrictMaxChar(ev.Name, eventSet.NameMaxChar) + " - " + Common.GetSettingValue(Collection.Catagory, ev.CatagoryId);
            lblDescription.Font.Bold = false;
            string text = StringHelper.RestrictMaxChar(HttpUtility.HtmlDecode(ev.Description), eventSet.DetailsMaxChar);
            StringHelper.ConvertToHtmlText(ref text);
            lblDescription.Text = text;
            lblOrganiser.Font.Bold = true;
            lblOrganiser.Text = Common.GetImageTextLink("ShowUser.aspx?id=" + ev.Organiser.UserID, "Images/dj/user.gif", StringHelper.RestrictMaxChar(ev.Organiser.FName + " " + ev.Organiser.LName, eventSet.NameMaxChar), 15);
            bool viewEvent = false;
            if (ev != null && ev.Access != EventAccess.Private)
            {
                viewEvent = true;
            }
            else
            {
                if (ev.AccessCode == c)
                    viewEvent = true;
                else
                {
                    cAccess.Visible = true;
                    cAccess.UserId = ev.Organiser.UserID;
                    if (c != "" && c != null)
                        cAccess.Message = ResourceHelper.Get("MSG_InvalidCode");
                    else
                        cAccess.Message = ResourceHelper.Get("MSG_EvAccessPrivate");
                }
            }
            if (viewEvent)
            {
                Dictionary<string, string> kvList = new Dictionary<string, string>();
                kvList.Add("pi", "");
                tblTrans.Visible = true;
                btnPrev.Visible = false;
                btnNext.Visible = false;
                if (start > 1)
                {
                    btnPrev.Visible = true;
                    kvList["pi"] = Convert.ToString(pi - 1);
                    btnPrev.Attributes.Add("onclick", "javascript:window.location.href='" + Common.ResetUrl(kvList) + "'");
                }
                if (total > start + count)
                {
                    btnNext.Visible = true;
                    kvList["pi"] = Convert.ToString(pi + 1);
                    btnNext.Attributes.Add("onclick", "javascript:window.location.href='" + Common.ResetUrl(kvList) + "'");
                }
                eventSet.Event = ev;
            }
            else
            {
                btnPrev.Visible = false;
                btnNext.Visible = false;
            }
        }
        catch (Exception exc)
        {
            lblMessage.Text = "<br />&nbsp;&nbsp;" + Common.GetErrorText(exc.Message);
            btnPrev.Visible = false;
            btnNext.Visible = false;
            imgEvent.Visible = false;
            imgSlide.Visible = false;
        }
    }
}
